package com.yjt.javatest.controller;

import com.yjt.javatest.entity.User;
import com.yjt.javatest.service.UserService;
import com.yjt.javatest.utils.APIResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/user")
@Tag(name = "用户")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/register")
    @Operation(summary = "注册")
    public APIResponse register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/login")
    @Operation(summary = "登录",description = "response中已添加token,返回token，之后的请求请携带token访问")
    public APIResponse login(@RequestBody User user,HttpServletResponse response){
        return userService.login(user,response);
    }

    @PostMapping("/logout")
    @Operation(summary = "注销",description = "退出登录")
    public APIResponse logout() {
        return userService.logout();
    }

    @GetMapping
    @Operation(summary = "获取登录后的用户信息")
    public APIResponse getUserInfo() {
        return userService.getUserInfo();
    }


}
